package com.zygh.lz.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zygh.lz.entity.Staff;
import com.zygh.lz.entity.Xarea;
import com.zygh.lz.entity.bean.StaffBean;
import com.zygh.lz.entity.remould.Matching;
import com.zygh.lz.vo.ResultBean;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface StaffMapper extends BaseMapper<Staff> {
    int deleteByPrimaryKey(Integer sysStaffId);

    int insert(Staff record);

    int insertSelective(Staff record);

    Staff selectByPrimaryKey(Integer sysStaffId);

    Map selectStaffInfoById(Integer sysStaffId);

    int updateByPrimaryKeySelective(Staff record);

    int updateByPrimaryKey(Staff record);

    //登录
    Staff selectByLogin(@Param("user") String user, @Param("password") String password);

    //校验
    Staff selectByName(String name);

    //根据id查询该人的部门、路长等级和姓名
    Staff selectInfoByid(Integer staffId);

    Staff selectByPrimaryKeyBig(String sysStaffId);

    //关联查询所有人员
    List<Staff> selectAllStaff();

    //查询所有人员
    List<Staff> selectAllStaffPeople();

    int selectBySectionId(int id);

    List<Staff> selectdefault(String probleDetail);

    //查出每个大队下的人员
    List<Staff> selectAllBySF(Integer sysSectionId);

    List<Staff> selectStaffByName(@Param("Name") String Name, @Param("staffHierarchy") String staffHierarchy);

    //返回各大队指挥室
    Staff selectStaffBySectionName(Integer staffid);

    //根据警号查询人员信息
    Staff selectStaffByNum(String staffNum);

    Staff selectStaffByNums(String staffNum);

    //根据条件查询该中队的所有民警
    List<Staff> selectStaffByXarea(@Param("battalion") String battalion,
                                   @Param("detachment") String detachment,
                                   @Param("station") String station,
                                   @Param("leader") String leader);

    //查询区域里对应的警员
    List<Staff> selectStaffInfo();

    //根据gpsid查询区域民警
    List<Staff> selectStaffByGpsid(Integer id);

    //查询在岗人
    List<Staff> selectStaffByzg(@Param("sectionId") Integer sectionId,
                                @Param("sectionPid") Integer sectionPid,
                                @Param("sectionName") String sectionName);


    List<Staff> selectStaffByxarea(Integer id);

    List<Map> selectStaffByxareaId(Integer id);

    //所有应上岗人
    List<Staff> selectStaffYdByAll(@Param("changeShifts") String changeShifts,
                                   @Param("SectionId") Integer SectionId,
                                   @Param("SectionZid") Integer SectionZid);

    List<Staff> selectStaffSdByAll(String changeShifts);

    //查询所有在线民警，并把该民警岗位带出
    List<Staff> selectpoliceZx();

    //查询直系领导
    Staff selectStaffBypid(Integer id);

    //查询昨日总警力
    int selecttotalforces();

    //按大队查询昨日总警力
    List<HashMap> selecttotalforceszr();

    //根据岗位查询在岗人
    List<Staff> selectzaBystation(@Param("station") String station,
                                  @Param("conment") String conment,
                                  @Param("grid") String grid,
                                  @Param("battalion") String battalion);

    //查询其他在线民警
    List<Staff> selectStaffByqita();


    /**
     * 从下查询人数，首页右侧信息展示
     */
    //统计固定岗/高峰岗实到
    List<Staff> countGdorGfSDsum(@Param("station") String station,
                                 @Param("battalion") String battalion);

    List<Staff> countGdorGfSDsumtj();

    //统计夜巡实到
    List<Staff> countYxSDsum(String battalion);

    //统计铁骑实到
    List<Staff> countTqSDsum(String battalion);


    //根据岗位查询各大队在线民警
    List<HashMap> selectcountBysection(Xarea xarea);


    //根据岗位查询各大队下各中队在线民警
    List<HashMap> selectcountBydetachment(Xarea xarea);

    //根据岗位查询各中队在线民警详情
    List<HashMap> selectAllBysection(Xarea xarea);

    //根据岗位查询各中队在线民警详情
    List<HashMap> selectAllBysection(@Param("battalion") String battalion,
                                     @Param("station") String station,
                                     @Param("type") String type,
                                     @Param("conment") String conment);

    //民警辅警各大队分布详情
    List<HashMap> selecttotalforcfb(@Param("stafftype") String stafftype, @Param("battalion") String battalion);

    /**
     * 对接市局接口  人员信息列表
     *
     * @return
     */
    List<Staff> selectStaffByInfo();


    int updateInfo(Staff staff);

    //根据大队查询本大队的人员信息并带出区域
    List<Staff> findStaffInfo();

    //特殊勤务当班在线警力
    List<HashMap> specialOn(String sectionName);

    //根据部门特殊勤务当班在线详情
    List<HashMap> specialOnment(String sectionName);

    //个人详情
    Map<String, Object> findStaffByid(Integer id);

    //根据警号查询民警id
    Integer findIdByStaffTel(String id);


    List<Staff> selectStaffBySectionID(Integer sys_section_id);

    List<String> selectStaffBySectionPid(Integer sys_section_id);


    Staff findStaffByJH(String staffNum);

    int insertAll(List<Staff> staff);

    List<Map> findStaffByXareaId(Integer id);

    List<Map> findStaffByWarningSignal(@Param("sectionId") Integer sectionId,
                                       @Param("warningSignal") String warningSignal);

    //根据岗位和大队查询大队下部署警力（非平峰期）
    List<Map> findStaffByStation(@Param("sectionId") Integer sectionId,
                                 @Param("lochusId") Integer lochusId,
                                 @Param("station") String station,
                                 @Param("stafftype") String stafftype);

    //根据岗位和大队查询大队下部署警力(平峰期)
    List<Map> findStaffByFlat(@Param("sectionId") Integer sectionId,
                              @Param("lochusId") Integer lochusId,
                              @Param("stafftype") String stafftype);

    List<Map> findStaffInfoByAll(@Param("staffName") String staffName,
                                 @Param("warningsignal") String warningsignal,
                                 @Param("sectionid") Integer sectionid,
                                 @Param("staffType") String staffType);

    List<Map> selectStaffMatching(Matching matching);

    List<Map<String, Object>> selectStaffOnLine(Matching matching);

    List<Map<String, Object>> selectStaffOffLine(Matching matching);

    List<Map> selectCommandCenter();

    Staff findStaffByName(String name);

    Staff findStaffByNames(@Param("name") String name,
                           @Param("sectionname") String sectionname);


    Staff findStaffByID(String id);


    List<Staff> findchognfu();

    List<Staff> findByName(String name);

    List<Map<String, Object>> findByNames(String name);


    @Update("UPDATE staff SET sys_section_id = #{sysSectionId},staff_post = #{staffPost} ," +
            "staff_idcard = #{staffIdcard} ,cellphonenumber= #{cellphonenumber},digital_radio=#{digitalRadio} " +
            "WHERE staff_num = #{staffNum} ")
    int updateByStaffNum(Staff staff);

    @Update("UPDATE staff SET unit = #{unit} WHERE staff_num = #{staffNum} ")
    int updateByCode(Staff staff);


    List<Map<String, Object>> findStaffs();


    List<Long> getNavMenuIds(Long userId);

    @Select("select * from staff where stafftype = '管理员' and sys_staff_id in (select user_id from sys_user_role where role_id = #{roleId})")
    List<Staff> roleUser(Integer roleId);

    @Select("SELECT ac.staff_name from account ac " +
            " LEFT JOIN staff st on ac.sys_staff_id=st.sys_staff_id " +
            " where st.sys_section_id is not null and st.sys_section_id=#{sectionDid} limit 1")
    String findBySysStaffId(Integer sectionDid);
}